package com.example.kliven.because.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.example.kliven.because.R;
import com.example.kliven.because.Singleton.VolleySingleton;
import com.example.kliven.because.bean.FashionBean;

import java.util.List;

/**
 * Created by Kliven on 16/1/15.
 */
public class FashionAdapter extends BaseAdapter {

    private Context context;
    private List<FashionBean> fashionBeans;

    public FashionAdapter(Context context, List<FashionBean> fashionBeans) {
        this.context = context;
        this.fashionBeans = fashionBeans;
        VolleySingleton.getInstance(); // 封装获取网络图片;
    }

    @Override
    public int getCount() {
        return fashionBeans.size();
    }

    @Override
    public Object getItem(int i) {
        return fashionBeans;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        FashionViewHodler fashionViewHodler;
        String img = fashionBeans.get(i).getMain_img_url();
        if (view == null){
            view = LayoutInflater.from(context).inflate(R.layout.item_lv_fashion,viewGroup,false);
            fashionViewHodler = new FashionViewHodler(view);
            view.setTag(fashionViewHodler);
        } else {
            fashionViewHodler = (FashionViewHodler) view.getTag();
        }

        fashionViewHodler.tv_title.setText(fashionBeans.get(i).getTitle());
        fashionViewHodler.iv_img_url.setImageUrl(img,VolleySingleton.getImageLoader());
        return view;
    }

    class FashionViewHodler{
        TextView tv_title;
        NetworkImageView iv_img_url;

        public FashionViewHodler(View view) {
            tv_title = (TextView) view.findViewById(R.id.tv_titile);
            iv_img_url = (NetworkImageView) view.findViewById(R.id.net_img);
        }
    }
}
